package org.database.generator.code.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2019/8/27 10:33
 * @since
 */
public class DBUtils {


    public static Connection getConnection(){
        String url = Configuration.get("spring.datasource.url");
        String username = Configuration.get("spring.datasource.username");
        String password = Configuration.get("spring.datasource.password");
        String dirverClazz = Configuration.get("spring.datasource.driver-class-name");

        Connection connection = null;
        try {
            Class.forName(dirverClazz);
            connection = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static void close(Connection connection){
        if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }



}
